package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface UserMapper {
    @Select("select * from user where phone = #{phone}")
    User findByPhone(String phone);

    @Insert("insert into user(phone,status) values (#{phone},#{status})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void save(User user);

    @Select("select * from user where id=#{userId}")
    User findById(Long userId);

    List<Orders> userPage(@Param("page") Integer page, @Param("pageSize") Integer pageSize);

    List<Orders> page(@Param("number") Long number,
                      @Param("beginTime") Date beginTime,
                      @Param("endTime") Date endTime);

    @Select("select count(*) from orders")
    long findCount();
}
